<template>
  <input type="text" v-model="keyword">
  <h3>{{ keyword }}</h3>
</template>

<script>

import {customRef} from "vue";

export default {
  name: "App",
  components: {},
  setup(props, context) {
    function myRef(value) {
      let timer;
      return customRef((track, trigger) => {
        return {
          get() {
            track(); // 通知Vue追踪数据（value）的变化
            return value;
          },
          set(newVal) {
            clearTimeout(timer);
            // trigger(); // 通知Vue去重新解析模板
            timer = setTimeout(() => {
              value = newVal;
              trigger();
            }, 1000);
          },
        }
      })
    }

    // let keyword = ref('hello');
    let keyword = myRef('hello');
    return {
      keyword
    }
  }
}
</script>

<style scoped>

</style>